<%- @view_title = "Administration" -%>
<div class="andare">
    <div id="package-repositories" class="layout admin-entity">
        <div class="navigation">
            <%= render :partial => 'admin/package_repositories/list', :locals => {:scope => {:package_id => params[:package_id], :package_repositories => @package_repositories, :package_to_pipeline_map => @package_to_pipeline_map, :current_repo => @package_repositories.find(params[:repo_id]).getName()}} %>
        </div>
        <div class="content">
            <% if @package_configuration != nil %>
                <h2> Package Details</h2>
                <%= render :partial => "admin/shared/global_errors.html" -%>
                <div class="form">
                    <fieldset>
                        <div class="field">
                            <%= label_tag "package_name_value", "Package Name" %>
                            <%= text_field_tag "package_name_value", @package_configuration.name, :disabled => "true", :class => "important" %>
                        </div>
                        <%- @package_configuration.properties.each do |property| %>
                            <div class="field">
                                <%= label_tag "package_#{property.name}_value", property.display_name %>
                                <%= text_field_tag "package_#{property.name}_value", property.value, :disabled => "true" %>
                            </div>
                        <%- end %>
                    </fieldset>
                    <% if @package_to_pipeline_map.get(params[:package_id]) == nil %>
                        <div class="information">No Pipelines currently use this package</div>
                    <% else %>
                        <fieldset>
                            <legend><span>Pipelines currently associated with this package</span></legend>
                            <div id="pipelines_used_in">
                                   <a id="show_pipelines_used_in" href="#">Show pipelines using this package</a>
                            </div>
                        </fieldset>
                    <% end %>
                </div>


                <% if @package_to_pipeline_map.get(params[:package_id]) == nil %>
                    <%= form_for @package_configuration, :as => '', :url => {:action => "destroy", :repo_id => params[:repo_id], :package_id => params[:package_id]}, :html => {:id => :delete_package_form, :method => :delete} do |f| %>
                            <%= md5_field %>
                            <span id="trigger_package_delete_<%=params[:package_id]%>">
                                 <div class="form_buttons">
                                     <button type="button" class="submit" title="Delete this package." id="delete_button_<%=params[:package_id]%>">
                                         <span>Delete</span>
                                     </button>
                                 </div>
                                <%= render :partial => 'admin/shared/submit_with_prompt.html',
                                           :locals => {:scope => {:button_container=> "trigger_package_delete_#{params[:package_id]}", :button_id => "delete_button_#{params[:package_id]}",:message => "You are about to delete package #{@package_configuration.name}",:on_confirmation_js => "$('delete_package_form').submit()"}} %>
                            </span>
                    <% end %>
                <% else %>
                    <div class="form_buttons">
                        <button type="submit" class="submit" id="delete_package" disabled="disabled" title="This package is being used in one or more pipeline(s), cannot delete the package"><span>Delete</span></button>
                    </div>
                <% end %>
            <% end %>
        </div>
        <%= render :partial => 'shared/convert_tool_tips.html', :locals => {:scope => {}} %>
    </div>
</div>


<script type="text/javascript">
    Util.on_load(function () {
        var url = '<%= pipelines_used_in_path(:repo_id=>params[:repo_id], :package_id => params[:package_id]) %>';
        new FetchPipelinesUsingGivenPackage(url, "#show_pipelines_used_in", "#pipelines_used_in").init();
    });
</script>
